﻿var pattern = /^(-?\d+)(\.\d{1,3})?$/;

function getPriceStructure() {
    var percents = "";

    $("input[id^='input_percent_']").each(function(i, n) {
        var val = parseInt($(n).val()) / 100;
        var categoryId = $(n).attr("id");
        categoryId = categoryId.replace("input_percent_", "");

        if (val == "") {
            val = 0;
        }
        if (i == 0) {
            percents += categoryId + "|" + val;
        }
        else {
            percents += "," + categoryId + "|" + val;
        }
    });

    $("#hd_pricePercent").val(percents);
}
function checkNum(obj) {
    if (obj.value.length != 0) {
        if (pattern.test(obj.value)) {
        } else {
            obj.value = "0";
            obj.focus();
        }
    }
    else {
        obj.value = "0";
    }
}
function resetCategory() {
    $('#drp_parent').val('-1');
}

function resetByProduct() {
    $('#ddlRootCategory').val('-1');
    $('#ddlSubCategory').val('-1');
    $('#txtProductName').val("");
    $('#txtProductNo').val("");
}

function checkPrice(obj) {
    var trNode = $(obj).parent().parent(); //获取当前行的 tr
    var auto1 = trNode.children("td").get(3).innerHTML;         //获取第三个td中的值 ;原有的系统加价
    var auto2 = trNode.children().eq(4).children();       //获取第四个td中的input的值
    $('#hdCurrentOldAutoAdd').val(auto1);
    if (!pattern.test($(auto2).val())) {
        alert('请输入正确的系统加价比例!');
        $(auto2).focus();
        return false;
    } else {
        if (parseFloat($(auto2).val()) > 0) {
            $('#hdCurrentNewAutoAdd').val($(auto2).val());
            if (parseFloat(auto1) == parseFloat(auto2.val())) {
                alert("系统加价体系未产生变化！");
                return false;
            }
            else {
                return true;
            }
        }
    }
}